package com.github.threefish.sqltpldemo;

import com.github.threefish.spring.sqltpl.SqlTplResourceLoader;
import com.github.threefish.spring.sqltpl.annotation.EnableSqlTpl;
import com.github.threefish.spring.sqltpl.templte.beetl.BeetlSqlTemplteEngineImpl;
import com.github.threefish.sqltpldemo.dao.SqlDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 黄川 huchuc@vip.qq.com
 * date: 2020/3/14
 */
@SpringBootApplication
@EnableSqlTpl
public class SqlTplDemoApplication {

    public static void main(String[] args) {
        //开启热更新
        SqlTplResourceLoader.DEVELOPER_MODE = true;
        SpringApplication.run(SqlTplDemoApplication.class, args);
    }

    @Bean
    public BeetlSqlTemplteEngineImpl sqlTemplteEngine() {
        BeetlSqlTemplteEngineImpl beetlSqlTemplteEngine = new BeetlSqlTemplteEngineImpl();
        beetlSqlTemplteEngine.getGt().registerFunctionPackage("S", StringUtils.class);
        return beetlSqlTemplteEngine;
    }

    @RestController
    class SqlXmlRest {

        @Autowired
        SqlDao sqlDao;

        @GetMapping("/selectOne")
        public String selectOne() {
            return sqlDao.selectOne();
        }

        @GetMapping("/selectTwo")
        public String selectTwo() {
            return sqlDao.selectTwo();
        }
    }

}
